#!/usr/bin/env ruby

require "socket"

name     = ENV['GIT_AUTHOR_NAME']  || `git config user.name`
email    = ENV['GIT_AUTHOR_EMAIL'] || `git config user.email`
hostname = Socket.gethostname

@errors = []
case 
when !name, name.strip.empty?
  @errors << "You don't have an author name set."
  @errors << "Please set this to your real name before committing."
when !email, email.strip.empty?
  @errors << "You don't have an author email address set."
  @errors << "Please set this to your real email address before committing."
when name == "root", name =~ /^\s*$/
  @errors << "Your author name is '#{name}'."
  @errors << "Please set this to your real name before committing."
when email =~ /^\s*$/, email =~ /#{hostname}/
  @errors << "You author email is '#{email}'."
  @errors << "This matches part of the system hostname (#{hostname})."
  @errors << "If this is correct, please run again with --no-verify."
end

if @errors.size > 0
  puts @errors
  exit 1 
end
